home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93a.txt / 000015_icon-group-sender _Tue Jan 12 14:01:08 1993.msg < prev    next >
Internet Message Format  |  1993-04-21  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 12 Jan 1993 19:25:33 MST
  2. Date: Tue, 12 Jan 93 14:01:08 CST
  3. From: "Richard L. Goerwitz" <goer@midway.uchicago.edu>
  4. Message-Id: <9301122001.AA21292@midway.uchicago.edu>
  5. To: icon-group@cs.arizona.edu
  6. Subject: Pattern matching
  7. Status: R
  8. Errors-To: icon-group-errors@cs.arizona.edu
  9.  
  10. >Would it be feasible to have {SML, Miranda, Hope blabla}-style pattern
  11. >matching in Icon.  (More specifically, a case state that has patterns
  12. >instead of literals in the cases.)  I think it would fit in neatly
  13. >with the data constructors Icon has, and greatly increase its
  14. >useability for writing things like compilers in Icon, where you want
  15. >to branch on the structure of some data object rather than on a
  16. >specific object.
  17.  
  18. There are just so many bits of syntactic sugar one can add to a language
  19. before it becomes bloated.  Maybe I'm not understanding correctly what
  20. you mean, but I don't see anything wrong with:
  21.  
  22. while line := read() do {
  23.     line ? {
  24.         if match("this") then
  25.             X
  26.         else if match("that") then
  27.         Y
  28.     else if match("something else") then
  29.             Z
  30.     }
  31. }
  32.  
  33. Anyone who knows Icon will immediately recognize this code fragment as
  34. implementing a case-like structure for patterns rather than values.
  35.  
  36. Writing a compiler, though, really requires more than a simple set of
  37. scanning routines, so I'm not sure that this is what you want either.
  38. In most cases, deterministic lexical analyzers have to work on a charac-
  39. ter-by-character basis, with little or no backtracking.  The lexical
  40. analyzers then feed tokens to parsers that operate on stack structures,
  41. and don't read the input stream as such.  I keep hoping somebody with
  42. more theoretical background than I will post a good compiler compiler for
  43. Icon some day.
  44.  
  45.  
  46. -Richard Goerwitz
  47. goer@midway.uchicago.edu
  48.